package com.example.speechtotext.demos.web.config;

import com.example.speechtotext.demos.web.handler.SpeechWebSocketHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Configuration
@EnableWebSocket // 启用 WebSocket 功能
public class WebSocketConfig implements WebSocketConfigurer {

    @Autowired // 自动注入 SpeechWebSocketHandler
    private SpeechWebSocketHandler speechWebSocketHandler;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        // 注册 WebSocket 处理器，并指定访问路径
        registry.addHandler(speechWebSocketHandler,"/speech")
                .setAllowedOrigins("*"); // 设置允许跨域访问
    }
}